<template>
	<view class="swiperBg mt-10" >
		<block >
			<view class="swiper page_swiper circular fillet dot2 pd-lr10 " 
			 v-if="banners.length">
				<swiper
				 indicator-dots="true" 
				 :autoplay="true" 
				 :circular="circular"
				 :interval="interval" 
				 :duration="duration" 
				 indicator-color="rgba(255,255,255,0.6)" 
				 indicator-active-color="#fff"
				 :style="'height:'+(imageH+10)+'rpx;'"
				 :current="swiperCur"
				 @change="swiperChange"
				 >
					<block v-for="(item,index) in banners" :key="index">
						<swiper-item :class="{ active: index == swiperCur }">
							<view @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
								<image :src="item.pic" class="slide-image aa" :style="'height:'+ imageH +'rpx;'" mode="aspectFill"></image>
							</view>
						</swiper-item>
					</block>
				</swiper>
				<!-- <view class="dots" :class="'dot'+txtStyle">
					<block v-for="(item,index) in imgUrls" :key="index">  
						<view class="dot" :class="[docConfig == 1 ? 'square' : docConfig == 0 ? 'circular' : 'nodoc',index == swiperCur ? ' active' : '']"></view>  
					</block>  
				</view> -->
			</view>
		</block>
	</view>
</template>

<script>

	import {merPath} from "@/utils/index"
	export default {
		name: 'swiperBg',
		props: {
			banners: {
				type: Array,
				default: () => []
			},
			merId:{}
		},
		data() {
			return {
				indicatorDots: false,
				circular: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				imgUrls: [], //图片轮播数据
				// imageHeight: 190,
				imageH: 190,
				swiperCur: 0,
				swiperType: 1,
			};
		},
		watch: {
			imageH(nVal, oVal) {
				let self = this
				this.imageH = nVal
			}
		},
		created() {
		},
		mounted() {
			let that = this;
			
			// that.$nextTick(function() {
			// 	uni.getImageInfo({
			// 		src: that.setDomain(that.banners[0].pic),
			// 		success: function(res) {
			// 			if (res && res.height > 0) {	
			// 				let height = res.height * ((750-20) / res.width)
			// 				that.$set(that, 'imageH', height);	
			// 			} else {
			// 				that.$set(that, 'imageH', 375);
			// 			}
			// 		},
			// 		fail: function(error) {
			// 			that.$set(that, 'imageH', 375);
			// 		}
			// 	})
			// })
		},
		methods: {
			//替换安全域名
			setDomain: function(url) {
				url = url ? url.toString() : '';
				//本地调试打开,生产请注销
				if (url.indexOf("https://") > -1) return url;
				else return url.replace('http://', 'https://');
			},
			swiperChange(e) {
				let { current, source } = e.detail;
				if (source === 'autoplay' || source === 'touch') {
					this.swiperCur = e.detail.current;
				}
			},
			goDetail(item){
				
				var url = item.url;
				// #ifdef MP-ALIPAY
				if(item.name == '公交地铁'){
					uni.navigateToMiniProgram({
						appId: '2021003173665753', 
						path: '/pages/index/index',
						extraData: {
						},
						success(res) {
						   // 打开成功
						}
					})
					return;
				}
				// #endif
				this.$util.JumpPath(url);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.swiperBg {
		position: relative;
		z-index: 1;
		.colorBg {
			position: absolute;
			left: 0;
			top: 0;
			height: 130rpx;
			width: 100%;
		}
		.page_swiper {
			position: relative;
			width: 100%;
			box-sizing: border-box;
			height: auto;
			margin: 0 auto;
			border-radius: 10rpx;
			overflow-x: hidden;
			/* #ifdef MP */
			z-index: 20;
			/* #endif */
			/* 设置圆角 */
			&.fillet {
				.swiper-item, image, .acea-row.row-between-wrapper{
					border-radius: 10rpx;
				}
			}
			.swiper-item, image, .acea-row.row-between-wrapper {
				width: 100%;
				height:100%;
				margin: 0 auto;
			}
			swiper{
				width: 100%;
				display: block;
				height: auto;
			}
			image {
				transform: scale(0.93);
				transition: all 0.6s ease;
			}
			swiper-item.active {
				image {
					transform: scale(1);
				}
			}
		}
	}
	.item-img image{
		display: block;
		width: 100%;
	}
	::v-deep .dot0 .uni-swiper-dots-horizontal{
		left: 10%;
	}
	::v-deep .dot1 .uni-swiper-dots-horizontal{
		left: 50%;
	}
	::v-deep .dot2 .uni-swiper-dots-horizontal{
		left: 90%;
	}
</style>
